#pragma once
#include "Comm.h"

namespace COMM
{
	class COMM_API ThreadNullLock
	{
	public:
		virtual ~ThreadNullLock(void);
		virtual void Lock();
		virtual void UnLock();
	};

	class COMM_API ThreadLockGuard
	{
	public:
		ThreadLockGuard(ThreadNullLock* lock);
		~ThreadLockGuard(void);

	private:
		ThreadNullLock* m_lock;
	};

	class COMM_API ThreadLock : public ThreadNullLock
	{
		MYLIB_NONCOPIED_CLASS(ThreadLock);
	public:
		ThreadLock(void);
		~ThreadLock(void);
		
		virtual void Lock();
		virtual void UnLock();
	private:
#ifdef COMM_MSVC
		CRITICAL_SECTION m_cs;
#else
		pthread_mutex_t m_mutex;
#endif
	};
	
	class COMM_API ThreadFreeLock : public ThreadNullLock
	{
		MYLIB_NONCOPIED_CLASS(ThreadFreeLock);
	public:
		ThreadFreeLock(void);
		
		virtual void Lock();
		virtual void UnLock();
	private:
		volatile int m_threadid;
		volatile int m_lockcount;
	};

}





